package com.itheima;

import com.itheima.config.SpringConfig;
import com.itheima.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.sql.DataSource;
import javax.xml.crypto.Data;
import java.sql.SQLException;

public class AnnApp {
    public static void main(String[] args) throws SQLException {
        //1.解析配置类,获得容器
        ApplicationContext app = new AnnotationConfigApplicationContext(SpringConfig.class);
        //2.获取bean对象
        /*BookDao bookDao = app.getBean(BookDao.class);
        bookDao.save();*/
       /* BookService bookService = app.getBean(BookService.class);
        bookService.save()*/;
        DataSource dataSource = app.getBean(DataSource.class);
//        DataSource dataSource = (DataSource) app.getBean("data1");
//        DataSource dataSource = (DataSource) app.getBean("dataSource");
        System.out.println(dataSource.getConnection().isClosed());
    }
}

